package com.zjw.zy.datasource.dao;

import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.zjw.zy.bean.Tip;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/11/2 10:53
 */
@Dao
public interface TipsDao {
    @Insert
    void insertItem(@NonNull Tip item);


    @Delete
    void deleteItem(@NonNull Tip item);

    @Update
    void updateItem(@NonNull Tip item);


    @Query("SELECT * FROM tips ORDER BY time DESC")
    List<Tip> queryAll();


    @Query("SELECT * FROM tips WHERE isDone == :isDone ORDER BY time DESC")
    List<Tip> queryAllByDone(boolean isDone);

    @Query("SELECT * FROM tips WHERE tag ==:tag AND isDone ==:isDone ORDER BY time DESC")
    List<Tip> queryAllByTag(@NonNull String tag, boolean isDone);

    @Query("SELECT tag FROM tips GROUP BY tag ORDER BY tag")
    List<String> queryAllTags();

    @Query("SELECT * FROM tips WHERE tag LIKE :keyword ORDER BY time DESC")
    List<Tip> queryAllByKeyword(@NotNull String keyword);
}
